package com.ruoyi.project.remake.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.remake.domain.TBorrowApproval;
import com.ruoyi.project.remake.service.ITBorrowApprovalService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 借阅审批Controller
 * 
 * @author 孙山伟
 * @date 2020-12-23
 */
@RestController
@RequestMapping("/remake/approval")
public class TBorrowApprovalController extends BaseController
{
    @Autowired
    private ITBorrowApprovalService tBorrowApprovalService;

    /**
     * 查询借阅审批列表
     */
    @PreAuthorize("@ss.hasPermi('remake:approval:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBorrowApproval tBorrowApproval)
    {
        startPage();
        List<TBorrowApproval> list = tBorrowApprovalService.selectTBorrowApprovalList(tBorrowApproval);
        return getDataTable(list);
    }

    /**
     * 导出借阅审批列表
     */
    @PreAuthorize("@ss.hasPermi('remake:approval:export')")
    @Log(title = "借阅审批", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TBorrowApproval tBorrowApproval)
    {
        List<TBorrowApproval> list = tBorrowApprovalService.selectTBorrowApprovalList(tBorrowApproval);
        ExcelUtil<TBorrowApproval> util = new ExcelUtil<TBorrowApproval>(TBorrowApproval.class);
        return util.exportExcel(list, "approval");
    }

    /**
     * 获取借阅审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('remake:approval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tBorrowApprovalService.selectTBorrowApprovalById(id));
    }

    /**
     * 新增借阅审批
     */
    @PreAuthorize("@ss.hasPermi('remake:approval:add')")
    @Log(title = "借阅审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBorrowApproval tBorrowApproval)
    {
        return toAjax(tBorrowApprovalService.insertTBorrowApproval(tBorrowApproval));
    }

    /**
     * 修改借阅审批
     */
    @PreAuthorize("@ss.hasPermi('remake:approval:edit')")
    @Log(title = "借阅审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBorrowApproval tBorrowApproval)
    {
        return toAjax(tBorrowApprovalService.updateTBorrowApproval(tBorrowApproval));
    }

    /**
     * 删除借阅审批
     */
    @PreAuthorize("@ss.hasPermi('remake:approval:remove')")
    @Log(title = "借阅审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBorrowApprovalService.deleteTBorrowApprovalByIds(ids));
    }
}
